<style type="text/css">
	.layui-table-cell{
		height: auto; /* Layui的表格高度自适应 */
	}
</style>


<fieldset class="layui-elem-field layui-field-title">
  <legend>分类列表</legend>
</fieldset>

<table id="list" lay-filter="list"></table>

<script type="text/html" id="bar">
	{{# if (d.status==1) {  }}
	<a class="layui-btn layui-btn-sm" lay-event="recover">恢复</a>
	{{# } }}
	{{# if (d.status==0) { }}
	<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete">删除</a>
	{{# } }}
	<a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="edit">编辑</a>
</script>

<script type="text/html" id="pic">
	{{#
	if (d.picture != null) {
	}}
	<img src="/adminServer/upload/{{d.picture}}">
	{{#
	}
	}}
</script>

<script type="text/javascript">
	layui.use(['table', 'form'], function(){
		var table = layui.table;
		var form = layui.form;
		
		
		// Ajax异步请求数据, 渲染表格
		table.render({
			elem: '#list',
			url: '/adminServer/api/goodsSorts',
			where: {parent: 0},
			method: 'get',
			height: 500,
			page: true,	// 开启分页
			cols: [[
				{field: 'id', title: 'ID', width: 100},
				{field: 'name', title: '分类名',},
				{field: 'picture', title: '图片', templet: '#pic', width:200},
				{field: 'parent', title: '父分类', templet: function(d){
					return d.parentSort==null ? '' : d.parentSort.name; 
				}},
				{field: 'status', title: '状态', templet: function(d){
					return ['正常', '删除'][d.status];
				}, width: 100},
				{title: '操作', toolbar: '#bar', width: 150, fixed: 'right'}
			]],
			// 解析数据
			parseData: function(res){
				return {
					"code": 0,
					"msg": res.msg,
					"count": res.data.total,
					"data": res.data.list
				};
			},
			done: function(res, curr, count){
				// 固定列高度适应
				$(".layui-table-main  tr").each(function (index ,val) {
					$($(".layui-table-fixed .layui-table-body tbody tr")[index]).height($(val).height());
				});
			}
		});
	});
</script>